home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / brklyprl.lha / Emulator / Benchmarks / hanoi.pl < prev    next >
Encoding:
Text File  |  1989-04-14  |  340 b   |  16 lines

  1.  
  2. /* Copyright (C) 1988, 1989 Herve' Touati, Aquarius Project, UC Berkeley */
  3.  
  4. %    towers of hanoi ( hanoi ) for 8 disks
  5.  
  6. main :- hanoi(8).
  7.  
  8. hanoi(N) :- move(N,left,center,right).
  9.  
  10. move(0,_,_,_) :- !.
  11. move(N,A,B,C) :- M is N-1, move(M,A,C,B), inform(A,B), move(M,C,B,A).
  12.  
  13. inform(A,B) :- write([move,disk,from,A,to,B]), nl, fail.
  14. inform(_,_).
  15.  
  16.